<?php
class pCategoryAction extends pBaseAction {

    protected $resutOperates=array(
        'index'=>array('栏目列表','pCategory/index'),
        'add'=>array('添加栏目','pCategory/add'),
        'allocate'=>array('栏目授权','pCategory/allocate')
    );

    public function index(){
        $dao=new CategoryModel();
        $this->assign('allCategorys',$dao->getTree());
        $this->display();
    }

    public function add(){
        $dao=new CategoryModel();
        $this->assign('allCategorys',$dao->getTree());
        $this->display();
    }

    public function save(){
        $dao=new CategoryModel();
        $result=$dao->addCategory();
        if(false===$result){
            $this->fail('栏目保存失败',$dao->getError());
        }else{
            $this->ok('栏目保存成功','成功添加了名为<b>'.$result['name'].'</b>的栏目');
        }
    }

    /**
     * 栏目授权
     */
    public function allocate(){
        $step=$_GET['step'];
        if($step=='1'){
            //读取具有内容管理相关权限的用户列表
            $dao=new Model();
            $tablePrefix=C('DB_PREFIX');
            $usrs=$dao->field('distinct u.account,u.realname')
                ->table($tablePrefix.'node n,'.$tablePrefix.'access a,'.$tablePrefix.'user u')
                ->where('n.name=\'pContent\' and a.parentNodeId=n.id and u.role=a.role')
                ->findAll();
            if(!$usrs){
                return $this->fail();
            }
        }

    }

}
